import axios from '@/utils/request'



export function login(user) {
    return axios.post("/login", {
    username: user.username,
    password: user.password
})}

export function register(user) {
    return axios.post("/register", {
        username: user.username,
        password: user.password
    })
}

export function getMe() {
    return axios.get("/users/me")
}

export function updateUser(userInfo) {
    return axios.put("/users", {
        id: userInfo.id,
        email: userInfo.email,
        description: userInfo.description,
        fullName: userInfo.fullName, 
        gender: userInfo.gender,
        phoneNumber: userInfo.phoneNumber,
        address: userInfo.address,
        dateOfBirth: userInfo.dateOfBirth
    })
}

export function uploadAvatar(userId, file) {
    const formData = new FormData()
    formData.append('file', file)
    return axios.put(`/users/${userId}`, formData, {
        headers: {
            'Content-Type': 'multipart/form-data'
        }
    })
}

export function findUserById(id) {
    return axios.get(`/users/${id}`)
}


// userlike
export function createUserLike(userLikeDTO) {
    return axios.post('/user-like', {
        userId: userLikeDTO.userId,
        targetUserId: userLikeDTO.targetUserId,
        contentId: userLikeDTO.contentId,
        contentType: userLikeDTO.contentType
    })
}

export function deleteUserLike(data) {
    return axios.delete('/user-like', {
        data: {
            userId: data.userId,
            contentId: data.contentId,
            contentType: data.contentType
        }
    })
}

export function isLiked(userId, contentId) {
    return axios.get('/user-like/is-liked', {
        params: {
            userId: userId,
            contentId: contentId
        }
    })
}

export function getLikedContent(userId, pageNum, pageSize) {
    return axios.get('/user-like/contents', {
        params: {
            userId: userId,
            pageNum: pageNum,
            pageSize: pageSize
        }
    })
}

export function getReceiveLikes(userId, pageNum, pageSize) {
    return axios.get('/user-like/receive', {
        params: {
            userId: userId,
            pageNum: pageNum,
            pageSize: pageSize
        }
    })
}

export function markLikeAsRead(userLikeDTO) {
    return axios.put('/user-like/mark-as-read', {
        userId: userLikeDTO.userId,
        targetUserId: userLikeDTO.targetUserId,
        contentId: userLikeDTO.contentId,
        contentType: userLikeDTO.contentType
    })
}


//userfavorite
export function createUserFavorite(data) {
    return axios.post('/user-favorite', {
        userId: data.userId,
        contentId: data.contentId,
        contentType: data.contentType,
        folderId: data.folderId
    })
}

export function deleteUserFavorite(data) {
    return axios.delete('/user-favorite', {
        data: {
            userId: data.userId,
            contentId: data.contentId,
            contentType: data.contentType,
            folderId: data.folderId
        }
    })
}

export function isFavorite(userId, contentId) {
    return axios.get('/user-favorite/is-favorite', {
        params: {
            userId: userId,
            contentId: contentId
        }
    })
}
export function isFolderFavorite(userId, contentId, folderId) {
    return axios.get('/user-favorite/is-folder-favorite', {
        params: {
            userId: userId,
            contentId: contentId,
            folderId: folderId
        }
    })
}

export function getFavoriteContent(userId, favoriteFolderId, pageNum, pageSize) {
    return axios.get('/user-favorite/contents', {
        params: {
            userId: userId,
            favoriteFolderId: favoriteFolderId,
            pageNum: pageNum,
            pageSize: pageSize
        }
    })
}

//user follow
export function followUser(data) {
    return axios.post('/user-follow', {
        followerId: data.followerId,
        followingId: data.followingId
    })
}

export function unfollowUser(data) {
    return axios.delete('/user-follow', {
        data: {
            followerId: data.followerId,
            followingId: data.followingId
        }
    })
}

export function getFollowingUsers(followerId, pageNum, pageSize) {
    return axios.get(`/user-follow/following`, {
        params: {
            followerId: followerId,
            pageNum: pageNum,
            pageSize: pageSize
        }
    })
}

export function getFollowerUsers(followingId, pageNum, pageSize) {
    return axios.get(`/user-follow/followers`, {
        params: {
            followingId: followingId,
            pageNum: pageNum,
            pageSize: pageSize
        }
    })
}

export function isFollowing(followerId, followingId) {
    return axios.get('/user-follow/is-following', {
        params: {
            followerId: followerId,
            followingId: followingId
        }
    })
}


//folder
export function createFavoriteFolder(data) {
    return axios.post('/favorite-folders', {
        userId: data.userId,
        folderName: data.folderName
    })
}

export function deleteFavoriteFolder(data) {
    return axios.delete('/favorite-folders', {
        data: {
            userId: data.userId,
            folderName: data.folderName
        }
    })
}

export function getAllFavoriteFolders(userId) {
    return axios.get(`/favorite-folders/${userId}`)
}
